<template>
  <div>
    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column fixed prop="id" label="学号" width="150"></el-table-column>
      <el-table-column prop="name" label="姓名" width="150"></el-table-column>
      <el-table-column prop="nex" label="性别" width="150"></el-table-column>
      <el-table-column prop="step" label="系别" width="150"></el-table-column>
      <el-table-column prop="ill" label="病例" width="150"></el-table-column>
      <el-table-column prop="data" label="日期" width="150"></el-table-column>
      <el-table-column fixed="right" label="操作" width="150">
        <template #default="scope">
          <el-button @click="edit(scope.row)" type="text" size="small">修改</el-button>
          <el-button @click="deleteBook(scope.row) "type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        layout="prev, pager, next"
        page-size="6"
        :total="total"
        @current-change="page">
    </el-pagination>
  </div>
</template>

<script>
export default {
  methods: {

    //删除操作
    deleteBook(row){
      const _this = this
      axios.delete('http://localhost:8181/healthy/deleteById/'+row.id).then(function (resp) {
        _this.$alert('《'+row.name+'》已经删除成功', '消息', {
          confirmButtonText: '确定',
          callback: action => {
            window.location.reload()
          }
        });
      })
    },

    //修改操作
    edit(row) {

      this.$router.push({
        path: '/UpdateBingLi',
        query:{
          id:row.id
        }
      })
    },

    //当前在第'+currentPage+'页'
    page(currentPage){
      const _this = this
      axios.get('http://localhost:8181/healthy/findAll/'+currentPage+'/6').then(function (resp) {
        _this.tableData = resp.data.content
        _this.total = resp.data.totalElements
        //console.log(resp)
        //console.log(resp.data)
      })
    }
  },

  created() {
    // alert(1)
    const _this = this
    axios.get('http://localhost:8181/healthy/findAll/1/6').then(function (resp) {
      _this.tableData = resp.data.content
      _this.total = resp.data.totalElements
      //console.log(resp)
      //console.log(resp.data)
    })
  },
  data() {
    return {
      total: null,
      tableData: null
    }
  }
}
</script>
